package cetb.data;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import cetb.domain.Client;

public class JDBCClientDAO implements IClientDAO {

	public void insert(Connection conn, String uoid, Client c) {
		String sql = "INSERT INTO shop (OID, surname, dni, receiveOffers) VALUES (?, ?, ?, ?) ";
	    PreparedStatement stmt = null;

	    try {
	    	
	        stmt = conn.prepareStatement(sql);    
	        stmt.clearParameters();
	        stmt.setString(1, uoid);
	        stmt.setString(2, c.getSurname());
	        stmt.setString(3, c.getDni());
	        stmt.setBoolean(4, c.getReceiveOffers());
	                
	        stmt.executeUpdate(); 

	    } catch (SQLException e) {
	    	System.out.println("Message: " + e.getMessage());
	        System.out.println("SQLState: " + e.getSQLState());
	        System.out.println("ErrorCode: " + e.getErrorCode());
	    } finally {
	    	try {
	    		if (stmt != null) {
	    			stmt.close();	                
	    		}
	    	} catch (SQLException e) {
	        
	    	}
	    }
	}

}
